--TEST--
string MySQLndUhConnection::getSqlstate(resource $connection)
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
	require_once('config.inc');

	class proxy extends MySQLndUhConnection {
		public function getSqlstate($res) {
			printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));
			var_dump($ret = parent::getSqlstate($res));
			return $ret;
		}
	}

	$conn = mysqlnd_uh_test\connect::mysqli();
	mysqlnd_uh_test\query_test::mysqli($conn);
	$conn->kill($conn->thread_id);
	var_dump($conn->query("SELECT 1 FROM DUAL"));
	$err = $conn->sqlstate;
	$conn = mysqlnd_uh_test\connect::mysqli();
	var_dump($conn->query("SELECT 1 FROM DUALI"));
	$err2 = $conn->sqlstate;

	$conn = mysqlnd_uh_test\connect::mysqli();
	mysqlnd_uh_set_connection_proxy(new proxy());
	mysqlnd_uh_test\query_test::mysqli($conn);
	$conn->kill($conn->thread_id);
	var_dump($conn->query("SELECT 1 FROM DUAL"));

	if (($tmp = $conn->sqlstate) != $err)
		printf("[001] SQLState string has changed from %s to %s\n", $err, $tmp);

	if (($tmp2 = $conn->sqlstate) != $err)
		printf("[002] SQLState has changed from %s to %s\n", $err, $tmp2);

	$conn = mysqlnd_uh_test\connect::mysqli();
	var_dump($conn->query("SELECT 1 FROM DUALI"));
	if (($tmp = $conn->sqlstate) != $err2)
		printf("[003] SQLState string has changed from %s to %s\n", $err2, $tmp);

	class proxy2 extends MySQLndUhConnection {
		public function getSqlstate($res) {
			return "mysql";
		}
	}

	class proxy3 extends MySQLndUhConnection {
		public function getSqlstate($res) {
			return -1;
		}
	}

	class proxy4 extends MySQLndUhConnection {
		public function getSqlstate($res) {}
	}

	class proxy5 extends MySQLndUhConnection {
		public function getSqlstate($res) {
			return str_repeat("a", 4096);
		}
	}

	mysqlnd_uh_set_connection_proxy(new proxy2());
	var_dump($conn->sqlstate);

	mysqlnd_uh_set_connection_proxy(new proxy3());
	var_dump($conn->sqlstate);

	mysqlnd_uh_set_connection_proxy(new proxy4());
	var_dump($conn->sqlstate);

	mysqlnd_uh_set_connection_proxy(new proxy5());
	var_dump($conn->sqlstate);

	print "done!";
?>
--EXPECTF--
bool(false)
bool(false)
bool(false)
proxy::getSqlstate(array (
  0 => NULL,
))
string(5) "%s"
proxy::getSqlstate(array (
  0 => NULL,
))
string(5) "%s"
bool(false)
proxy::getSqlstate(array (
  0 => NULL,
))
string(5) "%s"
string(5) "mysql"

Warning: main(): (MySQLnd User Handler) The method MySQLndUhConnection::getSqlstate() did not return a string value as it should in %s on line %d
NULL

Warning: main(): (MySQLnd User Handler) The method MySQLndUhConnection::getSqlstate() did not return a string value as it should in %s on line %d
NULL

Warning: main(): (MySQLnd User Handler) The method MySQLndUhConnection::getSqlstate() should not return a string longer than MYSQLND_UH_SQLSTATE_LENGTH - 1 characters. The return value will be trimmed in %s on line %d
string(5) "aaaaa"
done!